#!/usr/bin/env python
#coding: utf8

import os
import web

import config
import login
import sessions
import access
from access import get_user
import admin

# For debugging use only
web.webapi.internalerror = web.debugerror

urls = (
    '/', 'index',
    '/login', 'login.omms_login',
    '/logout', 'login.omms_logout',
    '/admin', 'admin.index',
    '/top', 'admin.top',
    '/menu', 'admin.menu',
    '/main', 'admin.main',
    '/omsm_info', 'admin.omsm_info',
)

# detect lang
lang = os.listdir(os.getcwd() + '/language')
for i in lang:
    if '.' not in i and '__' not in i:
        config.lang.append(i)

config.lang.sort()
config.lang = list(set(config.lang))

# index page
class index:
    def GET(self):
        user = get_user()
        if not user:
            web.seeother('/login')
        else:
            web.seeother('/admin')

if __name__ == "__main__":
    web.run(urls, globals(), web.reloader)
